using SqlSugar;
using System.Linq.Expressions;

namespace zhwy.saas.api.Repository
{
    public interface IBaseRepository<TEntity> where TEntity : class, new()
    {
        #region 查询
        /// <summary>
        /// 根据主键获取实体
        /// </summary>
        Task<TEntity> GetByIdAsync(object id);

        /// <summary>
        /// 获取所有实体
        /// </summary>
        Task<List<TEntity>> GetAllAsync();

        /// <summary>
        /// 根据条件查询实体列表
        /// </summary>
        Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate);

        /// <summary>
        /// 根据条件查询分页数据
        /// </summary>
        Task<(List<TEntity> Items, int Total)> GetPagedListAsync(Expression<Func<TEntity, bool>> predicate, int pageIndex, int pageSize);
        #endregion

        #region 增删改
        /// <summary>
        /// 新增实体
        /// </summary>
        Task<bool> AddAsync(TEntity entity);

        /// <summary>
        /// 新增实体并返回带有自增ID的实体
        /// </summary>
        /// <param name="entity">要添加的实体</param>
        /// <returns>添加后的实体（包含自增ID）</returns>
        Task<TEntity> AddEntityAsync(TEntity entity);

        /// <summary>
        /// 批量新增实体
        /// </summary>
        Task<bool> AddRangeAsync(List<TEntity> entities);

        /// <summary>
        /// 更新实体
        /// </summary>
        Task<bool> UpdateAsync(TEntity entity);

        /// <summary>
        /// 批量更新实体
        /// </summary>
        Task<bool> UpdateRangeAsync(List<TEntity> entities);

        /// <summary>
        /// 删除实体
        /// </summary>
        Task<bool> DeleteAsync(TEntity entity);

        /// <summary>
        /// 根据主键删除实体
        /// </summary>
        Task<bool> DeleteByIdAsync(object id);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        Task<bool> DeleteRangeAsync(List<TEntity> entities);
        #endregion

        /// <summary>
        /// 获取 SqlSugarClient 实例
        /// </summary>
        ISqlSugarClient DbContext { get; }
    }
}